import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import br.ufpe.cin.dsoa.qos.service.registry.QosServiceRegistry;
import br.ufpe.cin.dsoa.qos.service.registry.impl.Data;
import br.ufpe.cin.dsoa.qos.service.registry.impl.QoSAttribute;
import br.ufpe.cin.dsoa.qos.service.registry.impl.QosServiceRegistryImpl;
import br.ufpe.cin.dsoa.qos.service.registry.impl.Statistics;


public class Teste {
	public static void main(String[] args) {
		QosServiceRegistry qosServiceRegistry = new QosServiceRegistryImpl();

		for (int i = 1; i < 3; i++) {
			for (int j = 1; j < 5; j++) {
				qosServiceRegistry.addQosData(new QoSAttribute("sId"+i,"opA", "cId1", (5+j), "ResponseTime"));
			}
			qosServiceRegistry.addQosData(new QoSAttribute("sId"+i, "cId1", 87, "Avalability"));
			qosServiceRegistry.addQosData(new QoSAttribute("sId"+i, "cId1", 3+i, "Throughput"));
		}
		
		//teste de verificacao por pid
		/*Map<String,Statistics> pid = qosServiceRegistry.getHistoricalData("sId3");
		if(null != pid){
			for(String key : pid.keySet()){
				System.out.println("chave " + key);
				System.out.println("media " + pid.get(key).getMean(1));
			}
		}*/

		//verificacao da lista de pids
		List<String> pids = new ArrayList<String>();
		pids.add("sId1");
		pids.add("sId2");
		pids.add("sId3");

		Map<String, Map<String, Statistics>> pidsPorAtr = qosServiceRegistry.getHistoricalData(pids);
		if(null != pidsPorAtr){
			for(String pidPorAtr: pidsPorAtr.keySet()){
				Map<String,Statistics> pidI = pidsPorAtr.get(pidPorAtr);
				if(null != pidI){
					for(String key : pidI.keySet()){
						System.out.println("pid " + pidPorAtr);
						System.out.println("chave " + key);
						//System.out.println("media: " + pidI.get(key).getMean(2));
						if(pidPorAtr.equals("sId2") && key.equals("opA.ResponseTime")){
							qosServiceRegistry.addQosData(new QoSAttribute("sId2","opA", "cId1", 10, "ResponseTime"));
							qosServiceRegistry.addQosData(new QoSAttribute("sId2","opA", "cId1", 8, "ResponseTime"));
						}
						//System.out.println("media 2: " + pidI.get(key).getMean(2));
						if(pidPorAtr.equals("sId2") && key.equals("opA.ResponseTime")){
							qosServiceRegistry.addQosData(new QoSAttribute("sId2","opA", "cId1", 11, "ResponseTime"));
						}
						//System.out.println("media 3: " + pidI.get(key).getMean(10));	
						
						for(Data item: pidI.get(key).getData()){
							System.out.println("value Item: " + item.getValue());
							System.out.println("timestamp Item: " + item.getTimestamp());
						}
					}
					
				}
				System.out.println("");
				System.out.println("");
				System.out.println("");

			}
		}
		

	}

}
